package main

import (
	"go-framework/mvc"
	"net/http"
)

func main() {
	/***创建实例****/
	framework := mvc.New("0.0.0.0:9000")
	framework.GET("/index", func(context *mvc.Context) {
		context.HTML(http.StatusOK, "<h1>Index Page</h1>", nil)
	})

	v1 := framework.Group("/v1", framework)
	v1.GET("/", func(c *mvc.Context) {
		c.HTML(http.StatusOK, "<h1>Hello Gee</h1>", nil)
	})

	v1.GET("/hello", func(c *mvc.Context) {
		// expect /hello?name=geektutu
		c.String(http.StatusOK, "hello %s, you're at %s\n", c.Query("name"), c.Path)
	})
	v2 := framework.Group("/v2", framework)
	{
		v2.GET("/hello/:name", func(c *mvc.Context) {
			// expect /hello/geektutu
			c.String(http.StatusOK, "hello %s, you're at %s\n", c.Param("name"), c.Path)
		})
		v2.POST("/login", func(c *mvc.Context) {
			c.JSON(http.StatusOK, mvc.H{
				"username": c.PostForm("username"),
				"password": c.PostForm("password"),
			})
		})

	}

	framework.Start()
	select {}
}
